$(function() {
	
	// fix views
	var countBox = $('.countBox').length;
	var boxOffset = new Array();

	
	var fixLeftMenuStyle = function(){
		$('#leftSide ul li:last-child').addClass('last');
		if ($('#leftSide ul li:last-child').hasClass('selected')) {
			$('#leftSide ul li:last-child').addClass('lastSelected');
		}
	}	
	$('#leftSide ul li').click(function(){
		var i = $(this).index();
		$('body').animate({
			scrollTop: boxOffset[i] - $('#header').innerHeight()
		},800, 'easeOutCubic');
			 
		$('.selected').removeClass('selected lastSelected');
		$(this).addClass('selected');
		fixLeftMenuStyle();
		return false;
	});
	var fixColumnHeight = function(){
		var chk = 0;
		//$('#serviceDetail .innerScroll').innerHeight($(window).innerHeight());
		$('#wrap').css('padding-top',$('#header').innerHeight());
		$("img").each(function() {
			$(this).one('load', function() {
				$(this).load();
				chk += 1;
				if (chk >= $("img").length) {
					
					$('#wrap').css('padding-top',$('#header').innerHeight());
					
					$("#serviceDetail").dialog({
						autoOpen: true,
					    width: '72%',
					    height: 'auto',
					    position: 'top',
					    modal: true,
					    closeOnEscape: true,
					    open:function(e,ui){
					    	$('.ui-widget-overlay').css('position', 'fixed').animate({
								opacity:0.6
							},750);
					    },
					    close:function(){
					    	$('.ui-widget-overlay').css('position', 'absolute').animate({
								opacity:0
							},350,function(){$(this).hide();});
					    }
					});
					
					if ($('#leftSide').innerHeight() > $('#rightSide').innerHeight()) {
						$('.sideBar').height($('#leftSide').innerHeight());
					} else {
						$('.sideBar').height($('#rightSide').innerHeight());
					}
					if ($('#content').innerHeight() > $('.sideBar').innerHeight()) {
						$('.sideBar').height($('#content').innerHeight());
					} else {
						$('#content').height($('.sideBar').innerHeight);
					}
					
					//
					for(i=0;i<countBox;i++)
					{
						boxOffset[i] = $('.countBox').eq(i).offset().top;
					}
					
					//
					$('.lightBoxContentNav ol li').css('line-height',$('.lightBoxContentNav ol li').height());
					$('.lightBox > ul > li')
					.hover(function(){
							$('.lightBoxContentNavBg', this).stop(true).animate({
								opacity:.7
							});
							$('.lightBoxContentNav', this).stop(true).fadeIn();
						},
						function(){
							$('.lightBoxContentNavBg', this).stop(true).animate({
								opacity:0
							});
							$('.lightBoxContentNav', this).stop(true).fadeOut();
						});
				}
			});
		});
	}
	
	$(window).scroll(function(){
		//console.clear();
		//console.log($(window).scrollTop() + ', ' + boxOffset[1]);
		var headerHeight = $('#header').innerHeight();
		if($(window).scrollTop() > headerHeight)
		{
			$('.sideBar .padding').stop(true).animate({
				'top': $(window).scrollTop()
				//'top': $(window).scrollTop() - headerHeight
			},2000,'easeOutCubic');
		}
		else
		{
			$('.sideBar .padding').stop(true).animate({
				'top': 0
			},2000,'easeOutCubic');
		}
		
		for(i=0;i<boxOffset.length;i++)
		{
			if($(window).scrollTop() >= boxOffset[i] - headerHeight && !$('#leftSide ul li').eq(i).hasClass('selected') && i != 0)
			{
				$('.selected').removeClass('selected lastSelected');
				$('#leftSide ul li').eq(i).addClass('selected');
				fixLeftMenuStyle();
			}
			else if(i == 0)
			{
				$('.selected').removeClass('selected lastSelected');
				$('#leftSide ul li').eq(0).addClass('selected');
				fixLeftMenuStyle();
			}	
		}	
	});
	
	$('.type2 .backBoard .imgShow img').eq(0).css('float','left');
	$('.type2 .backBoard .imgShow img').eq(1).css('float','right');
	$('.cooperationList li:last-child').css('margin-right', 0);
	// //end fix views

	//exec
	fixColumnHeight();
	fixLeftMenuStyle();
	$(window).resize(function(){
		fixColumnHeight();
	});
});